package csu.web.mypetstore.config;

import org.springframework.boot.system.ApplicationHome;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 匹配原路径结构
        String projectRoot = new ApplicationHome(getClass()).getDir().getParentFile().getParent();
        String imagePath = "file:" + projectRoot 
                + "/src/main/resources/images/";
        
        registry.addResourceHandler("/images/**")
                .addResourceLocations(imagePath);
    }
}